home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / sound / players / maplay.lin / text0000.txt < prev   
Encoding:
Text File  |  1994-03-28  |  5.7 KB  |  223 lines

  1. Hi everybody!  I've added support for the Linux sound driver to 
  2. Tobias Bading's very fine program maplay.  The original program
  3. can be found on sunsite.unc.edu in /pub/electronic-publications/IUMA
  4. This version only supports mono output, there wouldn't be too much
  5. point in implementing stereo, because the playback is already a little
  6. choppy as it is on my 486/66.  Pentium owners, enjoy! 
  7. Since the patches aren't too long, I'm including them in this message.
  8.  
  9.     Louis
  10.  
  11. ----------------------------CUT HERE---------------------------------------
  12. --- ./configuration.sh~    Mon Feb 21 12:29:48 1994
  13. +++ ./configuration.sh    Sat Mar 12 20:44:39 1994
  14. @@ -46,9 +46,15 @@
  15.       INCLUDEDIRS='-I/usr/gnu/lib/g++-include -I/usr/gnu/lib/gcc-lib/decstation/2.5.8/include'
  16.       LIBRARIES=
  17.       AUDIO_INCLUDES= ;;
  18. +  "Linux*")
  19. +    COMPILER=g++
  20. +    COMPILERFLAGS='-O2 -m486 -funroll-loops -Wall -DLINUX -DDAMN_INTEL_BYTE_ORDER'
  21. +    INCLUDEDIRS='-I/usr/g++-include/ -I/usr/lib/gcc-lib/i486-linux/2.5.8/include/'
  22. +    LIBRARIES= 
  23. +    AUDIO_INCLUDES='#include <sys/soundcard.h>' ;;
  24.    *) echo "This programm has not been tested on your type of machine yet!"
  25.       echo "Please modify the file configuration.sh according to your needs!"
  26.       exit
  27.  esac
  28.  
  29.  export COMPILER COMPILERFLAGS INCLUDEDIRS LIBRARIES
  30. --- ./maplay.c~    Mon Feb 21 12:28:18 1994
  31. +++ ./maplay.c    Sat Mar 12 19:28:25 1994
  32. @@ -213,17 +213,26 @@
  33.        Exit (1);
  34.      }
  35.  #else
  36. -// #ifdef your_machine
  37. -//    if (mode == single_channel || which_channels != both)
  38. -//      buffer = new your_Obuffer (your_parameters);    // mono
  39. -//    else
  40. -//      buffer = new your_Obuffer (your_parameters);    // stereo
  41. -// #else
  42. +#ifdef LINUX
  43. +  if (LinuxObuffer::class_suitable(
  44. +       (mode == single_channel || which_channels != both) ? 1 : 2 ))
  45. +  { 
  46. +    if(mode == single_channel || which_channels != both)
  47. +      buffer = new LinuxObuffer (1, header);
  48. +    else
  49. +      buffer = new LinuxObuffer (2, header);
  50. +  }
  51. +  else
  52. +  {
  53. +    cerr << "Sorry, no suitable audio device detected, please use stdout mode.\n";
  54. +    Exit(1);
  55. +  }
  56. +#else
  57.    {
  58.      cerr << "Sorry, no suitable audio device detected, please use stdout mode.\n";
  59.      Exit (1);
  60.    }
  61. -// #endif  // !your_machine
  62. +#endif  // !LINUX
  63.  #endif    // !SPARC
  64.  #endif    // !Indigo
  65.  
  66. --- ./obuffer.c~    Mon Feb 21 12:28:21 1994
  67. +++ ./obuffer.c    Sat Mar 12 19:42:43 1994
  68. @@ -75,7 +75,122 @@
  69.      bufferp[i] = buffer + i;
  70.  }
  71.  
  72. +#ifdef LINUX
  73.  
  74. +int LinuxObuffer::audio_fd = -1;
  75. +
  76. +int LinuxObuffer::open_audio_device (void)
  77. +{
  78. +  int fd;
  79. +
  80. +  if ((fd = open ("/dev/dsp", O_WRONLY | O_NDELAY, 0)) < 0)
  81. +    if (errno == EBUSY)
  82. +    {
  83. +      cerr << "Sorry, the audio device is busy!\n";
  84. +      exit (1);
  85. +    }
  86. +    else
  87. +    {
  88. +      perror ("can't open /dev/dsp for writing");
  89. +      exit (1);
  90. +    }
  91. +  return fd;
  92. +}
  93. +
  94. +LinuxObuffer::LinuxObuffer (uint32 number_of_channels, Header *header)
  95. +{
  96. +#ifdef DEBUG
  97. +  if (!number_of_channels || number_of_channels > MAXCHANNELS)
  98. +  {
  99. +    cerr << "LinuxObuffer: 0 < number of channels < " << MAXCHANNELS << "!\n";
  100. +    exit (1);
  101. +  }
  102. +#endif
  103. +  channels = number_of_channels;
  104. +  for (int i = 0; i < number_of_channels; ++i)
  105. +    bufferp[i] = buffer + i;
  106. +
  107. +  if (audio_fd < 0)
  108. +  {
  109. +    cerr << "Internal error, LinuxObuffer::audio_fd has to be initialized\n"
  110. +        "by LinuxObuffer::class_suitable()!\n";
  111. +    exit (1);
  112. +  }
  113. +
  114. +  // configure the device:
  115. +  int play_precision = 16;
  116. +  int play_stereo = channels-1;
  117. +  int play_sample_rate = header->frequency ();
  118. +
  119. +  if(
  120. +      ioctl(audio_fd, SNDCTL_DSP_SAMPLESIZE, &play_precision) == -1 ||
  121. +      ioctl(audio_fd, SNDCTL_DSP_STEREO, &play_stereo) == -1 ||
  122. +      ioctl(audio_fd, SNDCTL_DSP_SPEED, &play_sample_rate) == -1
  123. +    )
  124. +  {
  125. +    perror ("configuration of /dev/dsp failed");
  126. +    exit (1);
  127. +  }
  128. +}
  129. +
  130. +LinuxObuffer::~LinuxObuffer (void)
  131. +{
  132. +  sleep (1);
  133. +  close (audio_fd);
  134. +}
  135. +
  136. +
  137. +void LinuxObuffer::append (uint32 channel, int16 value)
  138. +{
  139. +#ifdef DEBUG
  140. +  if (channel >= channels)
  141. +  {
  142. +    cerr << "illegal channelnumber in LinuxObuffer::append()!\n";
  143. +    exit (1);
  144. +  }
  145. +  if (bufferp[channel] - buffer >= OBUFFERSIZE)
  146. +  {
  147. +    cerr << "buffer overflow!\n";
  148. +    exit (1);
  149. +  }
  150. +#endif
  151. +  *bufferp[channel] = value;
  152. +  bufferp[channel] += channels;
  153. +}
  154. +
  155. +
  156. +void LinuxObuffer::write_buffer (int)
  157. +{
  158. +  int length = (int)((char *)bufferp[0] - (char *)buffer);
  159. +  if (write (audio_fd, buffer, length) != length)
  160. +    cerr << "Warning: couldn't write all samples to /dev/dsp\n";
  161. +  for (int i = 0; i < channels; ++i)
  162. +    bufferp[i] = buffer + i;
  163. +}
  164. +
  165. +bool LinuxObuffer::class_suitable (int channels)
  166. +{
  167. +  if(channels != 1)
  168. +  {
  169. +    cerr << "Stereo output not supported--use mono or stdout\n";
  170. +    return False;
  171. +  }
  172. +  // check for the dsp audio device:
  173. +  audio_fd = open_audio_device ();
  174. +#ifdef DEBUG
  175. +  if (audio_fd != -1)
  176. +    cerr << "Opened Okay!\n";
  177. +  else
  178. +    cerr << "Error: " << errno << "\n";
  179. +#endif
  180. +
  181. +  if (audio_fd != -1)
  182. +    return True;
  183. +  else
  184. +    return False;
  185. +}
  186. +
  187. +#endif    /* LINUX */
  188.  
  189.  #ifdef Indigo
  190.  IndigoObuffer::IndigoObuffer (uint32 number_of_channels, Header *header)
  191. --- ./obuffer.h~    Mon Feb 21 12:28:21 1994
  192. +++ ./obuffer.h    Sat Mar 12 19:12:19 1994
  193. @@ -61,6 +61,25 @@
  194.    void    write_buffer (int fd);
  195.  };
  196.  
  197. +#ifdef LINUX
  198. +class LinuxObuffer : public Obuffer
  199. +{
  200. +  int16 buffer[OBUFFERSIZE];
  201. +  int16 *bufferp[MAXCHANNELS];
  202. +  uint32 channels;
  203. +  static int audio_fd;
  204. +
  205. +    static int open_audio_device(void);
  206. +
  207. +  public:
  208. +    LinuxObuffer (uint32 number_of_channels, Header *);
  209. +       ~LinuxObuffer (void);
  210. +  void    append (uint32 channel, int16 value);
  211. +  void    write_buffer (int dummy);
  212. +    static bool class_suitable(int);
  213. +
  214. +};
  215. +#endif
  216.  
  217.  #ifdef Indigo
  218.  // a class for direct sound output on SGI machines:
  219. ----------------------------------END-----------------------------------
  220.  
  221.  
  222.  
  223.